"""Batfish module definition."""

# Maven artifact lists
# Note: MODULE.bazel cannot use load() statements, but can define constants.
BATFISH_MAVEN_ARTIFACTS = [
    "com.carrotsearch:hppc:0.10.0",
    "com.fasterxml.jackson.core:jackson-annotations",
    "com.fasterxml.jackson.core:jackson-core",
    "com.fasterxml.jackson.core:jackson-databind",
    "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml",
    "com.fasterxml.jackson.datatype:jackson-datatype-guava",
    "com.fasterxml.jackson.datatype:jackson-datatype-jdk8",
    "com.fasterxml.jackson.datatype:jackson-datatype-jsr310",
    "com.fasterxml.jackson.jaxrs:jackson-jaxrs-base",
    "com.fasterxml.jackson.module:jackson-module-jaxb-annotations",
    "com.github.ben-manes.caffeine:caffeine:3.2.3",
    "com.google.auto.service:auto-service:1.1.1",
    "com.google.auto.service:auto-service-annotations:1.1.1",
    "com.google.auto.value:auto-value:1.11.1",
    "com.google.auto.value:auto-value-annotations:1.11.1",
    "com.google.code.findbugs:jsr305:3.0.2",
    "com.google.code.gson:gson:2.13.2",
    "com.google.errorprone:error_prone_annotations:2.45.0",
    "com.google.guava:guava",
    "com.google.guava:guava-testlib",
    "com.google.re2j:re2j:1.8",
    "com.ibm.icu:icu4j:76.1",
    "commons-beanutils:commons-beanutils:1.11.0",
    "commons-cli:commons-cli:1.11.0",
    "commons-io:commons-io:2.21.0",
    "dk.brics:automaton:1.12-4",
    "io.github.java-diff-utils:java-diff-utils:4.16",
    "jakarta.activation:jakarta.activation-api:1.2.2",
    "jakarta.annotation:jakarta.annotation-api:1.3.5",
    "jakarta.ws.rs:jakarta.ws.rs-api:2.1.6",
    "jakarta.xml.bind:jakarta.xml.bind-api:2.3.3",
    "junit:junit:4.13.2",
    "net.sourceforge.pmd:pmd-cli:7.19.0",
    "net.sourceforge.pmd:pmd-java:7.19.0",
    "org.antlr:antlr4:4.13.2:complete",
    "org.antlr:antlr4-runtime:4.13.2",
    "org.apache.commons:commons-collections4:4.5.0",
    "org.apache.commons:commons-configuration2:2.13.0",
    "org.apache.commons:commons-lang3:3.20.0",
    "org.apache.commons:commons-text:1.15.0",
    "org.apache.httpcomponents:httpclient:4.5.14",
    "org.apache.httpcomponents:httpcore:4.4.16",
    "org.apache.logging.log4j:log4j-api:2.25.2",
    "org.apache.logging.log4j:log4j-core:2.25.2",
    "org.apache.logging.log4j:log4j-slf4j-impl:2.25.2",
    "org.codehaus.jettison:jettison:1.5.4",
    "org.glassfish.grizzly:grizzly-framework:2.4.4",
    "org.glassfish.grizzly:grizzly-http-server:2.4.4",
    "org.glassfish.jersey.containers:jersey-container-grizzly2-http:2.47",
    "org.glassfish.jersey.core:jersey-client:2.47",
    "org.glassfish.jersey.core:jersey-common:2.47",
    "org.glassfish.jersey.core:jersey-server:2.47",
    "org.glassfish.jersey.inject:jersey-hk2:2.47",
    "org.glassfish.jersey.media:jersey-media-json-jackson:2.47",
    "org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2:2.47",
    "org.glassfish.jersey.test-framework:jersey-test-framework-core:2.47",
    "org.hamcrest:hamcrest:3.0",
    "org.jgrapht:jgrapht-core:1.5.2",
    "at.yawk.lz4:lz4-java:1.10.1",
    "org.mockito:mockito-core:5.20.0",
    "org.mockito:mockito-inline:5.2.0",
    "org.parboiled:parboiled-core:1.4.1",
    "org.parboiled:parboiled-java:1.4.1",
    "org.skyscreamer:jsonassert:1.5.3",
    "org.yaml:snakeyaml:2.5",
]

BATFISH_MAVEN_BOMS = [
    "com.fasterxml.jackson:jackson-bom:2.20.1",
    "com.google.guava:guava-bom:33.5.0-jre",
]

JOL_MAVEN_ARTIFACTS = [
    "org.openjdk.jol:jol-cli:0.16:full",
]

JMH_MAVEN_ARTIFACTS = [
    "org.openjdk.jmh:jmh-core:1.35",
    "org.openjdk.jmh:jmh-generator-annprocess:1.35",
]

module(
    name = "batfish",
    version = "0.0.0",
)

# Core Bazel dependencies
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "bazel_features", version = "1.38.0")

# Java rules and dependencies
bazel_dep(name = "rules_java", version = "9.2.0")
bazel_dep(name = "rules_jvm_external", version = "6.9")

# Python rules
bazel_dep(name = "rules_python", version = "1.6.3")

# Development tools
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.1", dev_dependency = True)

bazel_dep(name = "rules_shell", version = "0.6.1")

# Python toolchain
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    python_version = "3.10",
)
use_repo(python, "python_3_10")

# Maven dependencies
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

# Main Batfish Maven artifacts
maven.install(
    name = "maven",
    artifacts = BATFISH_MAVEN_ARTIFACTS,
    boms = BATFISH_MAVEN_BOMS,
    excluded_artifacts = ["org.hamcrest:hamcrest-core"],
    fetch_sources = True,
    # Bzlmod allows multiple modules to contribute artifacts to the same Maven
    # install. This suppresses the warning about protobuf also contributing to
    # the "maven" repository (it adds older versions of gson, error_prone, guava).
    known_contributing_modules = [
        "batfish",
        "protobuf",
    ],
    lock_file = "@batfish//:maven_install.json",
    repositories = [
        "https://repo1.maven.org/maven2",
    ],
    strict_visibility = True,
)

# Add exclusions to artifacts that need them
# Note: In bzlmod, exclusions cannot be inlined in the artifacts list using
# maven.artifact() with maven.exclusion() syntax like in WORKSPACE. Instead,
# we use maven.amend_artifact() to modify artifacts after declaration.
maven.amend_artifact(
    coordinates = "com.google.guava:guava-testlib",
    exclusions = ["junit:junit"],
)
maven.amend_artifact(
    coordinates = "org.glassfish.jersey.test-framework:jersey-test-framework-core",
    exclusions = ["junit:junit"],
)
maven.amend_artifact(
    coordinates = "org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-grizzly2",
    exclusions = ["junit:junit"],
)

# Exclude transitive deps from antlr4 (complete jar is standalone)
maven.amend_artifact(
    coordinates = "org.antlr:antlr4",
    exclusions = [
        "org.antlr:antlr-runtime",
        "org.antlr:antlr4-runtime",
        "org.antlr:ST4",
        "org.abego.treelayout:org.abego.treelayout.core",
        "com.ibm.icu:icu4j",
        "org.glassfish:javax.json",
    ],
)

# JOL Maven dependencies (GPL licensed, dev-only tool)
maven.install(
    name = "jol_maven",
    artifacts = JOL_MAVEN_ARTIFACTS,
    fetch_sources = True,
    lock_file = "@batfish//tools/jol:jol_maven_install.json",
    repositories = [
        "https://repo1.maven.org/maven2",
    ],
    strict_visibility = True,
)

# JMH Maven dependencies (GPL licensed, dev-only tool)
maven.install(
    name = "jmh_maven",
    artifacts = JMH_MAVEN_ARTIFACTS,
    fetch_sources = True,
    lock_file = "@batfish//tools/benchmarks:jmh_maven_install.json",
    repositories = [
        "https://repo1.maven.org/maven2",
    ],
    strict_visibility = True,
)
use_repo(maven, "jmh_maven", "jol_maven", "maven")

# Python pip dependencies
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
    hub_name = "pip",
    python_version = "3.10",
    requirements_lock = "@batfish//python:requirements.txt",
)
use_repo(pip, "pip")
